﻿using System;
using System.Net.Sockets;
using System.Net;
using System.IO;
public class AsynchIOServer {
	public static void Main2() {
		Console.WriteLine("Server");
		TcpListener tcpListener = new TcpListener(IPAddress.Parse("127.0.0.1"), 8180);
		tcpListener.Start();
		Socket socketForClient = tcpListener.AcceptSocket();
		if (socketForClient.Connected) {
			Console.WriteLine("Client connected");
			NetworkStream networkStream = new NetworkStream(socketForClient);
			StreamWriter streamWriter = new StreamWriter(networkStream);
			StreamReader streamReader = new StreamReader(networkStream);
			string theString = "Sending";
			Console.WriteLine("Write line to send to client");
			while (true) {
				theString = Console.ReadLine();
				streamWriter.WriteLine(theString);
				//Console.WriteLine(theString);
				streamWriter.Flush();
				theString = streamReader.ReadLine();
				Console.WriteLine(theString);
			}
			streamReader.Close();
			networkStream.Close();
			streamWriter.Close();
		}
		socketForClient.Close();
		Console.WriteLine("Exiting...");
	}
}